import {Component, OnInit, OnDestroy} from "@angular/core";
import {Page} from "./breadcrumb";
import {PageSubject} from "../../../util/page-subject";
import {LogUtil} from "../../../util/log-util";
import {Subscription} from "rxjs/Subscription";

@Component({
  selector: 'app-admin-breadcrumb',
  templateUrl: './admin-breadcrumb.component.html',
  styleUrls: ['./admin-breadcrumb.component.css']
})
export class AdminBreadcrumbComponent implements OnInit,OnDestroy {

  breadCrumb:Page;
  constructor(
    private pageSubject : PageSubject,
    private logUtil : LogUtil
  ) {
  }

  private subscription : Subscription;

  ngOnInit() {
    this.logUtil.debug("page订阅");
    this.subscribePage();
  }

  private subscribePage(){
    this.subscription = this.pageSubject.subscribePage().subscribe(
      (page : Page) => {
        if(!!page){
          this.logUtil.debug("当前页："+JSON.stringify(page));
          this.breadCrumb = new Page(page.homePageName,page.homePageUrl,page.curPageName,page.curOperName,page.paths);
        }
      }
    );
  }

  ngOnDestroy(){
    this.subscription.unsubscribe();
  }
}
